package com.keller.seckill.exception;

import com.keller.seckill.vo.RespBean;
import com.keller.seckill.vo.RespBeanEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHander {

    @ExceptionHandler(Exception.class)
    public RespBean exceptionHander(Exception e){
        if(e instanceof GlobalException){
            GlobalException globalException = (GlobalException) e;
            return RespBean.error(globalException.getRespBeanEnum());
        }
        return RespBean.error(RespBeanEnum.ERROR);
    }
}
